package com.bysj.yqsht.service.impl;


import com.bysj.yqsht.bean.Matchs;
import com.bysj.yqsht.bean.MatchsExample;
import com.bysj.yqsht.bean.Subject;
import com.bysj.yqsht.bean.SubjectExample;
import com.bysj.yqsht.bean.extend.SubjectExtend;
import com.bysj.yqsht.dao.SubjectMapper;
import com.bysj.yqsht.dao.extend.SubjectExtendMapper;
import com.bysj.yqsht.service.ISubjectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class ISubjectServicieImpl implements ISubjectService {

    @Resource
    private SubjectMapper subjectMapper;

    @Resource
    private SubjectExtendMapper subjectExtendMapper;

    @Override
    public List<Subject> findAll() {
        SubjectExample example = new SubjectExample();
        return subjectMapper.selectByExample(example);
    }

    @Override
    public List<Subject> findpage(int pageNum, int limit) {
        PageHelper.startPage(pageNum,limit);
        SubjectExample subjectExample = new SubjectExample();
        List<Subject> list1 = subjectMapper.selectByExample(subjectExample);
        PageInfo<Subject> data = new PageInfo<Subject>(list1);
        List<Subject> list = data.getList();
        return list;
    }

    @Override
    public void saveOrUpdate(Subject subject) {
        if(subject.getId() != null){
            subjectMapper.updateByPrimaryKey(subject);
        }else{
            subjectMapper.insert(subject);
        }
    }

    @Override
    public void deleteById(long id) {
        subjectMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<SubjectExtend> selectWithClass() {
        return subjectExtendMapper.selectWithClass();
    }
}
